# STAT 202 Project
# Feature Selection
# Author: Fatih Sunor
#####################################################

# Read data
rm(list = ls(all = TRUE));
train <- read.csv("training.csv",header=TRUE);
relevance <- c(as.numeric(train$relevance[]));
homepage <- c(as.numeric(train$is_homepage[]));
querylen <- c(as.numeric(train$query_length[]));
signal <- t(rbind(as.numeric(train$sig1[]),as.numeric(train$sig2[]),as.numeric(train$sig3[]),as.numeric(train$sig4[]),as.numeric(train$sig5[]),as.numeric(train$sig6[]),as.numeric(train$sig7[])));

# Some preliminary analysis
cor(homepage,relevance);
cor(querylen,relevance);
cor(signal,relevance);
cor((signal));
cor(log(signal),relevance)
plot(log(1+signal[,3]^1/2),log(1+signal[,5])^1/2);
cor(log(1+signal[,3]^1/2),log(1+signal[,5]^1/2));
feature<-t(rbind(signal[,1],signal[,2], log(sqrt(signal[,5]*signal[,6])+1),signal[,7]));

# Query size does not impact relevancy
# Homepage looks more important
# Signal 3 and 5 are strongly correlated, select 5 only.
# Avoid overfitting


plot(feature[,4], 1/sum(feature[,4]), type="l", lty=2, xlab="Signal 7", ylab="Density", main="Signal 7 Density")